<?php
	session_start();

	require_once("includes/connect.php");
	require_once("includes/function.php");

	$task = $_REQUEST["task"];
	$pet_id = $_REQUEST["pet_id"];

	$reason = $_REQUEST["reason"];

	$i_date = $_REQUEST["i_date"];

	$cheque_no = $_REQUEST["cheque_no"];
	$branch_name = $_REQUEST["branch_name"];
	$bank_name = $_REQUEST["bank_name"];

	$month = $_REQUEST["month"];
	$year = $_REQUEST["year"];

	$val=$_REQUEST["val"];
	
	$val1 = explode(",", $val);
	$val1 = implode("','",$val1);

	$db = new myDBS;
	$db->selectDB("account");

	switch ($task) {
		case "verify":
			$sql ="UPDATE tbl_salary SET verify_status = 'ผ่าน', verify_date = NOW() WHERE pet_id = '$pet_id'";

			break;
		case "cancel":
			$sql ="UPDATE tbl_salary SET verify_status = 'ยกเลิก', reason = '$reason', verify_date = NOW() WHERE  pet_id = '$pet_id'";
			break;
		case "approved":
			$sql ="UPDATE tbl_salary SET approved_status = 'อนุมัติ', approved_date = '$i_date'  WHERE pet_id = '$pet_id'";

			break;
		case "disapproval":
			$sql ="UPDATE tbl_salary SET approved_status = 'ไม่อนุมัติ', approved_date = NOW() WHERE pet_id = '$pet_id'";

			break;
		case "approvedCheque":
			$sql ="UPDATE tbl_salary SET cheque_status = 'อนุมัติ', cheque_date = '$i_date' WHERE cheque_no = '$cheque_no'";

			break;
		case "disapprovalCheque":
			$sql ="UPDATE tbl_salary SET cheque_status = 'ไม่อนุมัติ' WHERE cheque_no = '$cheque_no'";

			break;
		case "print":
			$sql ="UPDATE tbl_salary SET cheque_no = '$cheque_no', branch_name = '$branch_name', bank_name = '$bank_name', print_cheque_date = '$i_date', print_cheque_status = 'พิมพ์แล้ว' WHERE id in('$val1') and lvl1_id = '" .$_SESSION["lvl1_id"]. "' and approved_status =  'อนุมัติ' and month_year = '$year-$month'";
			
			break;
		case "paid":
			$sql = "UPDATE tbl_salary SET paid_status = 'จ่ายแล้ว', paid_date = NOW() WHERE cheque_no = '$cheque_no'";
			break;

	}
	//echo $sql;
	$db->runSQL($sql);
?>
